Skip to content

handle when divisor b is zero in all division methods in Division.Java#249

Closed
UmForgotMyName wants to merge 1 commit intophishman3579:masterfrom
UmForgotMyName:handle-zero-divisor
Closed

handle when divisor b is zero in all division methods in Division.Java#249
UmForgotMyName wants to merge 1 commit intophishman3579:masterfrom
UmForgotMyName:handle-zero-divisor

Conversation

@UmForgotMyName
Copy link
Copy Markdown

This PR modifies all methods in Division.java to handle when the divisor, b is zero. This prevents potential runtime errors and improves the robustness of the code.

@UmForgotMyName
Copy link
Copy Markdown
Author

after reviewing the code, each method in Division.java has a new if statement to throw an illegal argument error if the divisor b is zero.

public class Division {

public static final long division(int a, int b) {
if (b == 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catches if divisor b is 0

}

public static final long divisionUsingLoop(int a, int b) {
if (b == 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catches if divisor b is 0

}

public static final long divisionUsingRecursion(int a, int b) {
if (b == 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catches if divisor b is 0

}

public static final long divisionUsingMultiplication(int a, int b) {
if (b == 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catches if divisor b is 0

}

public static final long divisionUsingShift(int a, int b) {
if (b == 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catches if divisor b is 0

}

public static final long divisionUsingLogs(int a, int b) {
if (b == 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catches if divisor b is 0

@UmForgotMyName UmForgotMyName closed this by deleting the head repository Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant